<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/8/16
  Time: 15:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Mananger</title>
</head>
<body>
<c:set value="${pageContext.request.contextPath}" var="contextPath"/>
<h4>管理权限的页面</h4>
<c:if test="${requestScope.message!=null}">
    <span style="color: red"><c:out value="${requestScope.message}"/></span>
</c:if>
<form action="${contextPath}/auth?method=getAuthority" method="post">
    Name: <input type="text" name="name">
    <input type="submit" value="Submit">
</form>
<c:if test="${requestScope.user!=null}">
    ${requestScope.user.name}的权限是:
    <br/><br/>
    <form action="${contextPath}/auth?method=updateAuthority" method="post">
        <input type="hidden" name="username" value="${requestScope.user.name}">

        <c:forEach items="${requestScope.authorities}" var="auth">
            <c:set var="flag" value="false"/>
            <c:forEach items="${requestScope.user.authorities}" var="ua">
                <c:if test="${ua.id == auth.id}">
                    <c:set var="flag" value="true"/>
                </c:if>
            </c:forEach>
            <c:if test="${flag == true}">
                <input type="checkbox" name="authority" checked="checked" value="${auth.id}">${auth.displayName}
            </c:if>
            <c:if test="${flag == false}">
                <input type="checkbox" name="authority" value="${auth.id}">${auth.displayName}
            </c:if>
            <br><br>
        </c:forEach>
        <input type="submit" value="Update Authority">
    </form>
</c:if>
</body>
</html>
